package com.scalar.chiptrack.commons;

import java.util.Comparator;
import java.io.Serializable;

/**
 * User: Sujan
 * Date: Jan 21, 2009
 * Time: 1:48:38 PM
 */
public class ScreenFieldPropertyComparator implements Comparator, Serializable
{
    public int compare(Object obj1, Object obj2)
    {
        if ( !( obj1 instanceof FieldProperty) || !( obj2 instanceof FieldProperty ) )
        {
            throw new  ClassCastException();
        }
        int order1 = ((FieldProperty)obj1).getOrder();
        int order2 = ((FieldProperty)obj2).getOrder();
        int result = ( order1 < order2 ? -1 :( order1 == order2 ? 0 : 1) );
        if ( result == 0 )
        {
            result = ( ( FieldProperty )obj1 ).getFieldLabel().compareToIgnoreCase(( ( FieldProperty )obj2 ).getFieldLabel() );
        }
        return result;
    }
}
